<?php

namespace DP\AbstractFactory\Factories;

use Exception;
use DP\AbstractFactory\Factories\Abstracts\AbstractFactory;

class ColorFactory extends AbstractFactory
{
    public function getColorFactory($color)
    {
        if (!$color) {
            return null;
        }

        $color = ucfirst(strtolower($color));
        $class = 'DP\AbstractFactory\Worker\Color\\' . $color . 'Color';

        try {
            return new $class();
        } catch (Exception $e) {
            echo '实例化失败，错误信息：' . $e->getMessage();
            return null;
        }
    }
}
